const mongoose = require('mongoose');
const config = require('../config');


mongoose.connect(config.mongodb, {
    useNewUrlParser: true
});

let db = mongoose.connection;

db.once('open', () => {
    console.log('mongoose connect succes.');
});
db.on('error', err => {
    console.error(err);
});
db.on('close', () => {
    console.log('mongoose reconnect.')
    mongoose.connect(config.mongodb);
});

module.exports = mongoose;